<template>
    <div class="container">

        <div class="body_wrap">
            <el-card class="body_card" shadow="hover" ref="content_card">
                <div class="header_back_wrap">
                    <el-page-header @back="$router.back(-1)" :content="$route.meta.title" class="headerBack"></el-page-header>
                    <el-divider></el-divider>
                </div>

                <div class="form_content">
                    <div class="table_form_wrap">
                        <el-form ref="form" :model="form" :rules="rules" @keyup.enter.native="handleSubmit()" label-width="120px">
                            <el-form-item label="公司照片" prop="companyPic">
                                <el-input placeholder="" v-model="form.companyPic" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="公司名称" prop="companyName">
                                <el-input placeholder="" v-model="form.companyName" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="公司电话" prop="companyPhone">
                                <el-input placeholder="" v-model="form.companyPhone" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="姓名" prop="name">
                                <el-input placeholder="" v-model="form.name" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="手机号" prop="phone">
                                <el-input placeholder="" v-model="form.phone" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="代理地区" prop="area">
                                <el-input placeholder="" v-model="form.area" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="详情地址" prop="address">
                                <el-input placeholder="" v-model="form.address" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="创建时间" prop="ctime">
                                <el-input placeholder="" v-model="form.ctime" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="更新时间" prop="utime">
                                <el-input placeholder="" v-model="form.utime" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <!--
                            <el-form-item label="状态" prop="status">
                                <el-radio-group v-model="form.status">
                                    <el-radio-button :label="1">正常</el-radio-button>
                                    <el-radio-button :label="0">锁定</el-radio-button>
                                </el-radio-group>
                            </el-form-item>
                            <el-form-item label="性别" prop="sex">
                                <el-select v-model="form.sex" placeholder="请选择">
                                    <el-option label="男" value="男"></el-option>
                                    <el-option label="女" value="女"></el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="生日" prop="birthday">
                                <el-date-picker
                                    v-model="form.birthday"
                                    type="date"
                                    placeholder="选择日期"
                                    value-format="yyyy-MM-dd"
                                    style="width: 63%;">
                                </el-date-picker>
                            </el-form-item>
                            <el-form-item label="备注" prop="remarks">
                                <el-input v-model="form.remarks" type="textarea" :rows="4" placeholder="请输入内容" style="width: 80%;"></el-input>
                            </el-form-item>
                            -->

                        </el-form>
                    </div>
                </div>

                <div class="foot_submit">
                    <el-button @click="$router.back(-1)">返 回</el-button>
                    <el-button @click="handleSubmit" type="primary" :loading="submitLoading">提 交</el-button>
                </div>

            </el-card>
        </div>



    </div>
</template>

<script>
    export default {
        data() {
            return {
                submitLoading: false,
                form: {
                    companyPic: null,
                    companyName: null,
                    companyPhone: null,
                    name: null,
                    phone: null,
                    area: null,
                    address: null,
                    ctime: null,
                    utime: null
                },
                rules: {
                    companyPic: [
                        { required: true, message: '公司照片不能为空', trigger: 'blur' }
                    ],
                    companyName: [
                        { required: true, message: '公司名称不能为空', trigger: 'blur' }
                    ],
                    companyPhone: [
                        { required: true, message: '公司电话不能为空', trigger: 'blur' }
                    ],
                    name: [
                        { required: true, message: '姓名不能为空', trigger: 'blur' }
                    ],
                    phone: [
                        { required: true, message: '手机号不能为空', trigger: 'blur' }
                    ],
                    area: [
                        { required: true, message: '代理地区不能为空', trigger: 'blur' }
                    ],
                    address: [
                        { required: true, message: '详情地址不能为空', trigger: 'blur' }
                    ],
                    ctime: [
                        { required: true, message: '创建时间不能为空', trigger: 'blur' }
                    ],
                    utime: [
                        { required: true, message: '更新时间不能为空', trigger: 'blur' }
                    ],
                }
            }
        },

        created() {
            this.form.id = this.$route.query.id
        },

        mounted() {
            this.$nextTick(() => {
                if(this.form.id) {
                    this.getInfo(this.form.id)
                }
            })
        },

        methods: {

            /**
             * 详细信息
             */
            async getInfo(id) {
                if (id) {
                    const res = await this.$http({
                        url: '/mall/wmsagentinfo/info/' + id,
                        method: 'GET'
                    })
                    this.form = Object.assign({}, res.data)
                }
            },


            /**
             * 提交表单
             */
            async handleSubmit() {
                const refs = this.$refs
                this.submitLoading = true
                const valid = await refs['form'].validate().catch(() => {})
                if(valid) {
                    const res = await this.$http({
                        url: `/mall/wmsagentinfo/${!this.form.id ? 'save' : 'update'}`,
                        method: 'POST',
                        data: this.form
                    })
                    if (this.ResultMessage(res)) {
                        this.$router.back(-1)
                        refs['form'].resetFields()

                        this.submitLoading = false
                    } else {
                        this.submitLoading = false
                    }
                } else {
                    this.submitLoading = false
                }
            }
        }
    }
</script>

<style lang="scss" scoped>



</style>
